package com.ssh;

public class Reverse_7 {
	public static void main(String[] args) {
		System.out.println(reverse1(-121211001));
	}
	public static int reverse(int x) {
		StringBuffer sb = new StringBuffer();
		sb.append(x);
		sb.reverse();
		sb = sb.charAt(sb.length()-1)=='-' ? sb.deleteCharAt(sb.length()-1) : sb;
		System.out.println(sb);
		while (0 < sb.length() && sb.charAt(0) == '0') {
			sb.deleteCharAt(0);
		}
		if (x < 0) {
			sb.insert(0, "-");
		}
		sb = (sb.toString().equals("")) ? sb.append(0) : sb;
		long z = Long.parseLong(sb.toString());
		if (z > Integer.MAX_VALUE || z < Integer.MIN_VALUE) {
			return 0;
		}
        return Integer.parseInt(sb.toString());
    }
	public static int reverse1(int x) {
		long rev= 0;
	    while( x != 0){
	        rev= rev*10 + x % 10;
	        x= x/10;
	        if( rev > Integer.MAX_VALUE || rev < Integer.MIN_VALUE)
	            return 0;
	    }
	    return (int) rev;
    }
	
	
}
